package org.itstack.demo.design;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: fanYuLe
 * @CreateTime: 2023-12-20  17:07
 * @Description:
 */
public class LoginSsoDecorator extends SsoDecorator{
    private Logger logger = LoggerFactory.getLogger(LoginSsoDecorator.class);

    private static Map<String,String> authMap = new ConcurrentHashMap<>();

    static {
        authMap.put("huahua", "queryUserInfo");
        authMap.put("doudou", "queryUserInfo");
    }
    public LoginSsoDecorator(HandlerInterceptor handlerInterceptor){super(handlerInterceptor);}

    @Override
    public boolean preHandle(String request, String response, Object handler) {
        boolean success = super.preHandle(request, response, handler);
        if(!success){return false;}
        String userId = request.substring(8);
        String method = authMap.get(userId);
        logger.info("模拟单点登录方法拦截校验：{} {}",userId,method);
        //模拟方法校验
        return "queryUserInfo".equals(method);
    }
}
